<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<%@ page language="java" import="java.util.*" pageEncoding="utf-8" %>
<%@ include file="/common/taglibs.jsp" %>

<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <title>系统管理</title>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
    <meta http-equiv="Content-Language" content="zh-CN"/>
    <meta name="keywords" content="EDC"/>
    <meta name="description" content="EDC"/>
    <meta http-equiv="buffer" content="true"/>
    <meta http-equiv="pragma" content="no-cache">
    <meta http-equiv="cache-control" content="no-cache">
    <meta http-equiv="expires" content="0">
    <%@  include file="/common/favicon.jsp" %>
    <%@ include file="/common/util.jsp" %>

    <script type="text/javascript">
        $(document).ready(function () {
            var map = new BMap.Map("map"); // 创建地图实例
            var lng = '${customerInfo.lng }';
            var lat = '${customerInfo.lat }';
            if (_.isEmpty(lng) || _.isEmpty(lat)) {
                lng = 121.459501;
                lat = 31.066453;
                var point = new BMap.Point(lng, lat); //获取地图中心点
                map.centerAndZoom(point, 5);
            } else {
                var point = new BMap.Point(lng, lat); //获取地图中心点
                map.centerAndZoom(point, 15);
            }
            map.enableScrollWheelZoom(true);
            refreshPosition(point);

            var marker = new BMap.Marker(map.getCenter());  //设置地图覆盖物
            map.addOverlay(marker);
            marker.enableDragging();
            marker.addEventListener('mouseup', function () {
                var p = marker.getPosition();
                refreshPosition(p);
            });

            var local = new BMap.LocalSearch(map, {
                renderOptions: {map: map}
            });
            //查询地理位置
            $("#searchPosition").submit(function () {
                var area = $("#province").val();
                if (!area) area = "上海";
                var position = $("#position").val();
                if (position) {
                    var myGeo = new BMap.Geocoder();
                    myGeo.getPoint(position, function (point) {
                        if (point) {
                            map.centerAndZoom(point, 15);
                            marker.setPosition(point);
                            refreshPosition(point);
                        } else {
                            alert("没有查询到你的地址!");
                        }
                    }, area);
                }
                return false;
            })

            function refreshPosition(point) {
                $("#lng").val(point.lng);
                $("#lat").val(point.lat);
                //对设置的地图点进行解析
                var geoc = new BMap.Geocoder();  //设置地图解析器
                geoc.getLocation(point, function (rs) {
                    var addComp = rs.addressComponents;
                    $("#province").val(addComp.province);
                    $("#city").val(addComp.city);
                    $("#district").val(addComp.district);
                    $("#street").val(addComp.street);
                    $("#streetnumber").val(addComp.streetnumber);
                });
            }
        });
    </script>
</head>
<body>
<form id="customerInfoForm">
    <input type="hidden" id="id" name="id" value="${customerInfo.id }"/>
    <input type="hidden" id="lng" name="lng" value="${customerInfo.lng }"/>
    <input type="hidden" id="lat" name="lat" value="${customerInfo.lat }"/>
    <input type="hidden" id="province" name="province" value="${customerInfo.province }"/>
    <input type="hidden" id="city" name="city" value="${customerInfo.city }"/>
    <input type="hidden" id="district" name="district" value="${customerInfo.district }"/>
    <input type="hidden" id="street" name="street" value="${customerInfo.street }"/>
    <input type="hidden" id="streetnumber" name="streetnumber" value="${customerInfo.streetnumber }"/>
    <div id="map" style="height:500px; width:900px;"></div>
</form>
<form id="searchPosition" action="" style="height:50px; width:900px;padding-left: 10px;padding-top: 10px;">
    <label class="search_text">地址:&nbsp;</label>
    <input type="text" id="position" name="position" class="search_input" style="width:200px">
    <input id="search" type="submit" class="search_btn" value="查&nbsp;询">
</form>
</body>
</html>